import { getHistoricalTmp } from "@/services/weather";
import { defineStore } from "pinia";

const useTmpStore = defineStore("tmp", {
  state: () => ({
    year: "",
    month: "",
    legend: [],
    maxTmp: [],
    minTmp: [],
    avgTmp: [],
  }),
  actions: {
    async fetchTmpData(city, code, year, month) {
      const res = await getHistoricalTmp(city, code, year, month);
      this.year = res.year;
      this.month = res.month;
      this.legend = res.legend;
      this.maxTmp = res.maxTmp;
      this.minTmp = res.minTmp;
      this.avgTmp = res.avgTmp;
    },
  },
});

export default useTmpStore;
